home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / InternalWindowPanel.java < prev    next >
Text File  |  1998-06-30  |  7KB  |  205 lines

  1. /*
  2.  * @(#)InternalWindowPanel.java    1.13 98/02/06
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. import com.sun.java.swing.*;
  22. import com.sun.java.swing.border.*;
  23. import com.sun.java.accessibility.*;
  24.  
  25. import java.awt.Panel;
  26. import java.awt.Color;
  27. import java.awt.BorderLayout;
  28. import java.awt.GridLayout;
  29. import java.awt.Font;
  30. import java.awt.event.ActionListener;
  31. import java.awt.event.ActionEvent;
  32. import java.awt.Dimension;
  33. import java.awt.Graphics;
  34. import java.awt.Color;
  35. import java.awt.Rectangle;
  36. import java.awt.Container;
  37.  
  38. /*
  39.  * 1.13 98/02/06
  40.  * @author Dave Kloba
  41.  * @author Peter Korn (accessibility support)
  42.  */
  43. public class InternalWindowPanel extends JPanel implements ActionListener     {
  44.     // Maker values
  45.     JCheckBox closeBox;
  46.     JCheckBox maxBox;
  47.     JCheckBox iconBox;
  48.     JCheckBox resizeBox;
  49.     JTextField titleField;
  50.     JTextField layerField;
  51.     JButton closeAllButton;
  52.     JButton makeButton;
  53.     JLayeredPane lc;
  54.     int makeCount = 0;
  55.     JInternalFrame maker;
  56.  
  57.     public InternalWindowPanel()    {
  58.         setLayout(new BorderLayout());
  59.         lc = new JDesktopPane();
  60.     lc.setOpaque(false);
  61.         maker = createMakerFrame();
  62.         lc.add(maker, JLayeredPane.PALETTE_LAYER);  
  63.         
  64.         add("Center", lc);
  65.     }
  66.  
  67.     public JInternalFrame createMakerFrame() {
  68.         JInternalFrame w;
  69.         JPanel tp;
  70.     Container contentPane;
  71.         
  72.         w = new JInternalFrame("Frame Creator");
  73.     contentPane = w.getContentPane();
  74.         contentPane.setLayout(new GridLayout(0, 1));
  75.  
  76.         tp = new JPanel();
  77.         tp.setLayout(new GridLayout(2, 2));
  78.         closeBox = new JCheckBox( "is Closable ");
  79.         closeBox.setSelected(true);
  80.         tp.add(closeBox);
  81.         maxBox = new JCheckBox(   "is Maxable  ");
  82.         maxBox.setSelected(true);
  83.         tp.add(maxBox);
  84.         iconBox = new JCheckBox(  "is Iconifiable ");
  85.         iconBox.setSelected(true);
  86.         tp.add(iconBox);
  87.         resizeBox = new JCheckBox("is Resizable");
  88.         resizeBox.setSelected(true);
  89.         tp.add(resizeBox);
  90.         contentPane.add(tp);
  91.         
  92.         tp = new JPanel();
  93.     tp.setBorder(BorderFactory.createTitledBorder("Title"));
  94.         tp.setLayout(new BorderLayout());
  95.         titleField = new JTextField();
  96.         titleField.setText("");
  97.         titleField.setMinimumSize(new Dimension(50, 25));
  98.     titleField.setEditable(true);
  99.     titleField.getAccessibleContext().setAccessibleName("Title for created frame");
  100.         tp.add(titleField, "Center");
  101.         contentPane.add(tp);              
  102.  
  103.         tp = new JPanel();
  104.     tp.setBorder(BorderFactory.createTitledBorder("Layer"));
  105.         tp.setLayout(new BorderLayout());
  106.         layerField = new JTextField();
  107.         layerField.setMinimumSize(new Dimension(50, 25));
  108.     layerField.setEditable(true);
  109.         layerField.setText("5");
  110.     layerField.getAccessibleContext().setAccessibleName("Layer for created frame");
  111.     layerField.getAccessibleContext().setAccessibleDescription("This must be an Integer value, which determines which layer in the stacking order to place the newly created Internal Frame");
  112.         tp.add(layerField, "Center");
  113.         contentPane.add(tp);              
  114.  
  115.         tp = new JPanel();
  116.         tp.setLayout(new GridLayout(1, 2));
  117.         closeAllButton = new JButton("Clear");
  118.         closeAllButton.addActionListener(this);
  119.         tp.add(closeAllButton);
  120.         makeButton = new JButton("Make");
  121.         makeButton.addActionListener(this);
  122.         tp.add(makeButton);     
  123.         contentPane.add(tp);
  124.         
  125.         w.setBounds(360, 10, 270, 250);
  126.         w.setResizable(true);
  127.         return w;
  128.     }
  129.  
  130.     public void actionPerformed(ActionEvent e) {
  131.         if(e.getSource() == closeAllButton) {
  132.             lc.removeAll();
  133.             lc.add(maker);
  134.             lc.repaint();
  135.             makeCount = 0;
  136.         } else if(e.getSource() == makeButton) {
  137.             JInternalFrame w;
  138.         int layer;
  139.             w = new JInternalFrame();
  140.             w.setClosable(closeBox.isSelected());
  141.             w.setMaximizable(maxBox.isSelected());
  142.             w.setIconifiable(iconBox.isSelected());
  143.         String title = titleField.getText();
  144.         if(title.equals("")) {
  145.                 w.setTitle("Internal Frame " + (makeCount+1));
  146.         } else {
  147.                 w.setTitle(title);
  148.         }
  149.             w.setResizable(resizeBox.isSelected());
  150.         try { 
  151.                 layer = Integer.parseInt(layerField.getText()); 
  152.         } catch (NumberFormatException e2) {
  153.             layer = 0;
  154.         }
  155.             makeCount++;
  156.             w.setBounds(20*(makeCount%10), 20*(makeCount%10), 225, 150);
  157.             w.setContentPane(new MyScrollPane(layer, makeCount));
  158.                 
  159.             lc.add(w, new Integer(layer));  
  160.             try { w.setSelected(true); } catch (java.beans.PropertyVetoException e2) {}
  161.         }
  162.     }
  163.  
  164. }
  165.  
  166. class MyScrollPane extends JScrollPane
  167. {
  168.     static ImageIcon[] icon = new ImageIcon[5];
  169.  
  170.     public MyScrollPane(int layer, int count)
  171.     {
  172.     super();
  173.         if(icon[0] == null) {
  174.            icon[0] = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/misc/horn.gif", "Horn");
  175.            icon[1] = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/misc/fish.gif", "Fish");
  176.            icon[2] = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/misc/moon.gif", "Moon");
  177.            icon[3] = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/misc/sun.gif",  "Sun");
  178.            icon[4] = SwingSet.sharedInstance().loadImageIcon("images/ImageClub/misc/cab.gif",  "Yellow Cab");
  179.         }
  180.     JPanel p = new JPanel();
  181.            p.setOpaque(false);
  182.     p.setLayout(new BorderLayout() );
  183.     JLabel layerLabel = new JLabel("Layer "+layer);
  184.     layerLabel.setOpaque(false);
  185.         
  186.     int it = count%5;
  187.         p.add(new JLabel(icon[count%5]), BorderLayout.CENTER);
  188.     p.add(layerLabel, BorderLayout.NORTH);
  189.  
  190.     getViewport().add(p);
  191.  
  192.     }
  193.     
  194.     public Dimension getMinimumSize() {
  195.     return new Dimension(25, 25);
  196.     }
  197.     
  198.     public boolean isOpaque() {
  199.         return true;
  200.     }
  201. }
  202.  
  203.  
  204.  
  205.